// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System.Collections.Generic;

namespace SnapObjects.Data
{
    internal abstract class SqlConditionStatementGenerator : SqlStatementGenerator
    {
        public SqlConditionStatementGenerator(
            ISqlStatementFactory factory,
            ISqlGenerationHelper helper,
            ITypeMapper typeMapper) : base(factory, helper, typeMapper)
        {
        }

        protected override IReadOnlyList<SqlToken> SpliceStatement(SqlStatement statement)
        {
            var tokens = new List<SqlToken>();

            if (statement.StatementType == SqlStatementType.Condition)
            {
                var condition = (SqlConditionStatement)statement;

                tokens.AddRange(this.SpliceClause(condition.Condition));
            }
            else
            {
                tokens.AddRange(base.SpliceStatement(statement));
            }

            return tokens;
        }
    }
}
